package com.ecommerce.payment.repository;

import com.ecommerce.payment.entity.Payment;
import com.ecommerce.payment.entity.PaymentStatus;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface PaymentRepository extends JpaRepository<Payment, Long> {
   default Payment findByOrderNoAndStatus(String orderNo, PaymentStatus status) {
       // 根据订单号和状态，查询支付记录
       return findAll().stream()
               .filter(payment -> payment.getOrderNo().equals(orderNo) && payment.getStatus() == status)
               .findFirst()
               .orElse(null);
   }

    default Optional<Payment> findByPaymentNo(String paymentNo){
        return findAll().stream()
                .filter(payment -> payment.getPaymentNo().equals(paymentNo))
                .findFirst();
    }
}